package com.lesson01;

//多个线程同时操作同一个对象
//线程不安全
public class TestThread04 implements Runnable{
    //票数
    private int ticketNums = 10;

    @Override
    public void run() {
        while(true){
            if(ticketNums <= 0){
                break;
            }

            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "拿到了" + ticketNums--);
        }
    }

    public static void main(String[] args) {
        //创建一个测试对象
        TestThread04 ticket = new TestThread04();

        //创建两个线程
        new Thread(ticket,"小明").start();
        new Thread(ticket,"老师").start();
        new Thread(ticket,"黄牛").start();
    }
}
